﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Diploma.Models;
using Diploma.Models.Entities;
using DiplomaWeb.Models.Student;
using StudentEntity = Diploma.Models.Student;

namespace DiplomaWeb.Models.CompaniesAndLecturers
{
    public class LecturerPracticeViewModel
    {
        #region Properties

        public Guid Id { get; set; }
        public string FIO { get; set; }
        public List<LecturerLevelInfoViewModel> Levels { get; set; }
        public List<StudentViewModel> Students { get; set; }
        public IEnumerable<SelectListItem> SelectListStudents
        {
            get
            {
                return DataProvider.StudentsRepository.GetMagisterStudentsWithoutPractice()
                    .Select(r => new SelectListItem
                                     {
                                         Value = r.UserId.ToString(),
                                         Text = String.Format("{0} {1}", r.StudentsGroup.Name, r.FullName)
                                     });
            }
        }

        #endregion

        #region Public

        public void ToViewModel(Lecturer lecturer,
            IEnumerable<LecturersForPractice> practices,
            IEnumerable<LecturerInCompanyEntity> companies,
            IEnumerable<StudentEntity> students)
        {
            Id = lecturer.UserId;
            FIO = lecturer.FullName;

            Levels = new List<LecturerLevelInfoViewModel>();
            foreach (LecturersForPractice item in practices)
            {
                var model = new LecturerLevelInfoViewModel();
                model.ToViewModel(item, companies);
                Levels.Add(model);
            }

            Students = new List<StudentViewModel>();
            foreach (StudentEntity student in students)
            {
                var model = new StudentViewModel();
                model.ToViewModel(student);
                Students.Add(model);
            }
        }

        #endregion

        #region Providers

        private static DataManager DataProvider
        {
            get { return DataManager.Instance; }
        }

        #endregion
    }
}